<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var arr = [10,20,30];
    var i = 0;
    var sum = 0;
    function foo(){
        if (i>=arr.length){
            alert(sum/arr.length);
            clearInterval(timer)
        } else {
            sum += arr[i];
        }
        i++;
    }
    var timer = setInterval(foo,200);



</script>
</body>
</html>